package com.itheima01;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TreeMap;

public class Test01 {
    public static void main(String[] args) throws ParseException {
        File file = new File("C:\\Users\\阳光正直夏明伟15805655221\\Desktop\\测试\\itheima");
        ArrayList<File> dirlist = new ArrayList<>();
        ArrayList<File> list = new ArrayList<>();

        diGui(file, dirlist, list);
       TreeMap<String, String> mp = new TreeMap<>();
        for (File file1 : list) {
            long haomiao = file1.lastModified();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
            String format = sdf.format(new Date(haomiao));
            String path = file1.getPath();
            mp.put(format, path);

        }
      mp.entrySet().forEach(s -> System.out.println(s));
//        for (int i = 0; i < mp.keySet().size(); i++) {
//            SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//            Date parse = sdf.parse(mp.get(i));
//            long time = parse.getTime();
//        }
    }

    public static void diGui(File file, ArrayList<File> dirlist, ArrayList<File> list) {
        if (file.isFile()) {
            list.add(file);
        }
        if (file.isDirectory()) {
            dirlist.add(file);
            File[] files = file.listFiles();
            if (files != null) {
                for (File file1 : files) {
                    diGui(file1, dirlist, list);
                }
            }
        }
    }
}
